import 'package:flutter/material.dart';
import 'package:my_translate/const/const_page.dart';

class RecordingTranslate extends StatefulWidget {
  const RecordingTranslate({Key? key}) : super(key: key);

  @override
  _RecordingTranslateState createState() => _RecordingTranslateState();
}

class _RecordingTranslateState extends State<RecordingTranslate> {
  List<Translate> _itmes = [
    Translate("Drawer", "抽屉", true),
    Translate("title", "subTitle", false),
    Translate("title", "subTitle", false),
    Translate("title", "subTitle", false)
  ];

  @override
  Widget build(BuildContext context) {
    return Expanded(
        child: ListView.builder(
            itemCount: _itmes.length,
            itemBuilder: (context, index) {
              return _displayList(index);
            }));
  }

  Widget _displayList(int index) {
    return Container(
      padding: EdgeInsets.only(top: 2.0, bottom: 2.0, left: 2.0, right: 2.0),
      child: Card(
        shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.all(Radius.circular(0.0))),
        margin: EdgeInsets.only(left: 8.0, right: 8.0),
        child: Container(
          padding: EdgeInsets.only(left: 15.0, top: 15.0, bottom: 15.0),
          height: 80.0,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [_flexible(index), _collection(index)],
          ),
        ),
      ),
    );
  }

  Flexible _flexible(int index) {
    return Flexible(
        child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisAlignment: MainAxisAlignment.spaceAround,
      children: [
        Text(
          _itmes[index].title,
          style: Theme.of(context).textTheme.headline6,
          maxLines: 1,
          overflow: TextOverflow.ellipsis,
        ),
        Text(
          _itmes[index].subTitle,
          style: TextStyle(color: Colors.grey[600],fontSize: 15.0),
          maxLines: 1,
          overflow: TextOverflow.ellipsis,
        ),
      ],
    ));
  }

  _collection(int index) {
    return IconButton(
      onPressed: () {
        setState(() {
          _itmes[index].isCollection = !_itmes[index].isCollection;
        });
      },
      icon: Icon(_itmes[index].isCollection ? Icons.star : Icons.star_border),
      iconSize: 25.0,
      color: _itmes[index].isCollection ? Colors.yellow[600] : Colors.grey[700],
    );
  }
}
